package zhengyanze.com.aipoemmax.guide.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.SaveCallback;

import zhengyanze.com.aipoemmax.R;
import zhengyanze.com.aipoemmax.guide.guide.GuideActivity;
import zhengyanze.com.aipoemmax.guide.utils.AppConfigUtiles;
import zhengyanze.com.aipoemmax.guide.utils.LogUtils;

public class WelcomeActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);

        // 测试 SDK 是否正常工作的代码
//        AVObject testObject = new AVObject("TestObject");
//        testObject.put("words","Hello World!");
//        testObject.saveInBackground(new SaveCallback() {
//            @Override
//            public void done(AVException e) {
//                if (e == null) {
//                    Log.d("saved","success!");
//                }
//            }
//        });

        setContentView(R.layout.activity_welcome);
        handler.postDelayed(runnable, 2000);
    }

    Handler handler = new Handler();

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            boolean isFirst = AppConfigUtiles.getAppConfigUtiles().getGuide(WelcomeActivity.this);
            if (isFirst){
                startActivity(new Intent(WelcomeActivity.this,GuideActivity.class));
            }else{
                startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
            }
            finish();
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }
}
